<!doctype html>
<html lang="en">
  <head>
    <title>医院挂号</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
  </head>
  <body>
      
    <div id="app">
        <!-- 组件1：导航栏  b4-navbar-->
        <nav class="navbar navbar-expand-md  navbar-dark" style="background-color: #0991f3;">
            <a class="navbar-brand" href="#">{{title}} 🏥 </a>
            <div class="collapse navbar-collapse" id="collapsibleNavId">
                <!-- 在这个导航栏中定义每一个选项 -->
                <ul class="navbar-nav mr-auto mt-2 mt-lg-0">
                    <!-- 一个选项就是一个li标签 -->
                    <li class="nav-item active ml-3">
                        <a class="nav-link" href="#">首页<span class="sr-only">(current)</span></a>
                    </li>
                    <li class="nav-item ml-3">
                        <a class="nav-link" href="#">文件</a>
                    </li>
                    <!-- 有下拉选项的li标签 -->
                    <li class="nav-item dropdown ml-3">
                        <a class="nav-link dropdown-toggle" href="#" id="dropdownId" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">编辑</a>
                    <!-- 下拉选项的值 -->
                        <div class="dropdown-menu" aria-labelledby="dropdownId">
                            <a class="dropdown-item" href="#">撤销</a>
                            <a class="dropdown-item" href="#">恢复</a>
                            <a class="dropdown-item" href="#">剪切</a>
                            <a class="dropdown-item" href="#">复制</a>
                        </div>
                    </li>
                    <li class="nav-item dropdown ml-3">
                        <a class="nav-link dropdown-toggle" href="#" id="dropdownId" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">选择</a>
                    <!-- 下拉选项的值 -->
                        <div class="dropdown-menu" aria-labelledby="dropdownId">
                            <a class="dropdown-item" href="#">撤销</a>
                            <a class="dropdown-item" href="#">恢复</a>
                            <div class="dropdown-divider"></div>
                            <a class="dropdown-item" href="#">剪切</a>
                            <a class="dropdown-item" href="#">复制</a>
                        </div>
                    </li>
                </ul>
                <form class="form-inline my-2 my-lg-0">
                    <input class="form-control mr-sm-2" type="text" placeholder="Search">
                    <button class="btn btn-danger my-2 my-sm-0" type="submit">Search</button>
                </form>
            </div>
        </nav>
        <!-- 组件2：展板 b4-jum -->
        <div class="jumbotron jumbotron-fluid py-3">
            <div class="container">
                <!-- dispaly-1/5:表示字体大小 -->
                <h1 class="display-4">线上挂号系统</h1>
                <p class="lead">{{title}}</p>
            </div>
                <!-- 可以添加其他的内容包括组件  面包屑导航  b4-bread -->
            <nav class="breadcrumb">
                <span class="breadcrumb-item active">科室导航</span>
                <a class="breadcrumb-item" href="departscheduling.html" v-if="curDepart!=null">{{curDepart}}排班</a>
                <a class="breadcrumb-item" href="index.html" v-else>请选择科室</a>
                <a class="breadcrumb-item" href="patient.html">就诊人管理</a>
                <a class="breadcrumb-item" href="reservationinfo.html">我的预约信息</a>
            </nav>
        </div>
        <!-- 核心部分 -->
        <div class="container" id="app">
            <!-- 整个是一行 -->
            <div class="row">
                <!-- 左边 -->
                <div class="col-lg-3 col-md-2 col-sm-12">
                    <!-- 列表 -->
                    <h1 class="lead">科室导航</h1>
                    <!-- 快捷  b4-list-default -->
                    <ul class="list-group">
                        <!-- b4-list-a 快捷键
                        先通过li标签循环department这个数组，得到一个部门对象
                        循环一级部门的sub属性，这个属性是一个数组，得到下级部门-->
                        <li class="list-group-item" 
                         v-for="(depart, index) in department" :key="index">
                            {{depart.title}}
                            <div class="list-group">
                                <a  v-for="(subdepart, index) in depart.sub" :key="index"
                                    @click="getCurrDepartment(subdepart)"
                                    class="list-group-item list-group-item-action ">
                                    {{subdepart.title}}
                                </a>
                                <!--当我们点击的时候触发 getCurrDepartment方法，传递当前科室id和名字-->
                            </div>
                        </li>

                    </ul>
                </div>
                <!-- 右边 -->
                <div class="col-md-8 col-12">   
                    <h1 class="lead">名医导航</h1>
                    <!-- 卡片：图片展示一个内容   b4-card-grid   -->
                    <div class="row">
                        <!-- 占的列 遍历所有的医生，得到医生的对象-->
                        <div class="col-md-3 col-sm-6 col-6 mb-3" 
                        v-for="(doc, index) in doctor" :key="index">
                            <div class="card">
                                <!-- 添加一个图片 -->
                                <img :src="doc.img" width="100%" height="130px"/>
                                <div class="card-body text-center">
                                    <h3 class="card-title">{{doc.name}}</h3>
                                    <p class="card-text">{{doc.level}}</p>
                                    <p class="card-text">{{doc.department.title}}</p>
                                </div>
                                <!-- 点击挂号的时候，传递一个医生对象 -->
                                <a @click="getDoctor(doc)" type="button" class="btn btn-outline-danger">挂号</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- 页脚&网址地图 -->
        <div class="jumbotron jumbotron-fluid mb-0 mt-5 py-3">
            <div class="container">
                <p class="lead text-center">copyright 牛耳教育@2022</p>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script> 
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
  </body>
</html>
<script>
    var url = `http://39.108.176.33:8080`;
    // newvue---快捷
    const vm = new Vue({
        el:"#app", //当前vue对象渲染的页面  //vm.mount("#app")
        data() {
            return {
                title:"林科大东方医院",
                curDepart:null,
                // 部门信息,data
                department:null,  
                //医生信息
                doctor:[]
             }
        },
        mounted() { //生命周期，当data中有数据了，但是我们还没有放到页面上去
            this.getallDepartment();  //调用了查询所有的函数
        },
        methods: {
            getDoctor(doctor){
                //将医生信息传递到doctor页面
                sessionStorage.setItem("doctor",JSON.stringify(doctor));
                //跳转到doctor页面
                window.location.href="doctor.html";
            },
            /**查找所有的部门信息
             */ 
            getallDepartment(){
                //查询一般使用get：查询  post 添加  put 修改   delete 删除
                axios.get(`${url}/api/department`)
                .then(function (response) {
                    //response表示返回的数据对象，这个里面有很多的内容
                    vm.department = response.data;
                })
                .catch(function (error) {
                    //出现错误会返回一个error
                    console.log(error);
                })
            },
            //设置科室名字到sessionStorage中
            setSeesion(depart){
                sessionStorage.setItem("curDepart",depart);
            },
            //拿到当前科室的id和当前科室的名字
            getCurrDepartment(curdepart){
                //情况上一次查询的部门医生
                this.doctor = [];
                this.curDepart = curdepart.title;
                //修改了当前科室的名字，所以重新设置
                this.setSeesion(JSON.stringify(curdepart));
                //拿到科室的id，通过科室的id找到当前的所有医生
                axios.get(`${url}/api/doctor/${curdepart.id}`)
                .then((response)=>{
                    this.doctor = response.data;
                })
                .catch(function (error) {
                })
            }
        },
    })

</script>